<?php

/**
 * This is the model class for table "tb_ebooks".
 *
 * The followings are the available columns in table 'tb_ebooks':
 * @property integer $ID
 * @property string $ref_code
 * @property string $cat_id
 * @property string $title
 * @property string $detail
 * @property string $fileupload
 * @property string $file_type
 * @property string $post_date
 * @property integer $view
 */
class TbEbooks extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return TbEbooks the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_ebooks';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ref_code, cat_id, title, detail, fileupload, file_type, post_date', 'required'),
			array('view', 'numerical', 'integerOnly'=>true),
			array('ref_code', 'length', 'max'=>7),
			array('cat_id', 'length', 'max'=>1),
			array('title', 'length', 'max'=>70),
			array('detail', 'length', 'max'=>250),
			array('fileupload', 'length', 'max'=>20),
			array('file_type', 'length', 'max'=>3),
			array('post_date', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID, ref_code, cat_id, title, detail, fileupload, file_type, post_date, view', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID' => 'ID',
			'ref_code' => 'Ref Code',
			'cat_id' => 'Cat',
			'title' => 'Title',
			'detail' => 'Detail',
			'fileupload' => 'Fileupload',
			'file_type' => 'File Type',
			'post_date' => 'Post Date',
			'view' => 'View',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID',$this->ID);
		$criteria->compare('ref_code',$this->ref_code,true);
		$criteria->compare('cat_id',$this->cat_id,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('detail',$this->detail,true);
		$criteria->compare('fileupload',$this->fileupload,true);
		$criteria->compare('file_type',$this->file_type,true);
		$criteria->compare('post_date',$this->post_date,true);
		$criteria->compare('view',$this->view);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}